package com.gengzp.common.enums;

import com.gengzp.common.exception.BusinessException;
import lombok.Getter;

/**
 * @ClassName ServiceFrontBackTypeEnum
 * @Description 服务前后端类型枚举类
 * @Author gengzp
 * @Date 2025/10/14 11:11
 */
@Getter
public enum ServiceFrontBackTypeEnum {

    FRONT_END(0, "前端"),

    BACK_END(1, "后端");

    private final Integer code;
    private final String value;

    ServiceFrontBackTypeEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public static String getValueByCode(Integer code) {
        for (ServiceFrontBackTypeEnum value : ServiceFrontBackTypeEnum.values()) {
            if (value.getCode().equals(code)) {
                return value.getValue();
            }
        }
        throw BusinessException.get(String.format("枚举值不关联, 枚举类: %s,枚举值: %s", ServiceFrontBackTypeEnum.class, code));
    }

    public static Integer getCodeByValue(String value) {
        for (ServiceFrontBackTypeEnum value1 : ServiceFrontBackTypeEnum.values()) {
            if (value1.getValue().equals(value)) {
                return value1.getCode();
            }
        }
        throw BusinessException.get(String.format("枚举值不关联, 枚举类: %s,枚举值: %s", ServiceFrontBackTypeEnum.class, value));
    }

}
